برنامه ی ساده ی بعدی : پیدا کردن بزرگترین عدد
الگوریتم:
ابتدا برای نگه داری اعداد جهت مقایسه ،متغیر تعریف می کنیم، سپس اعداد یکی یکی با متغیر max
مقایسه می شوند و عدد بزرگتر در max قرار داده می شود
++c
|
#c |
|
#include #include
int main() { int max = 0, i=0; int num; cout<<"\npress {a...Z} TO 'FINISH'."; cout<<"\n enter your number :"; while( cin>>num ) { max = (max < num)?num:max; } cout<<"the maximum number is : "<<max; getch(); return 0; }
|
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
int max=0; private void button1_Click_1(object sender, EventArgs e) { max = (max < Int32.Parse(txt1.Text)) ? Int32.Parse(txt1.Text) : max; lbl2.Text = (lbl2.Text + txt1.Text + ","); lbl3.Text = ("maximum is : " + max); txt1.Clear(); }
} } |
|
:: موضوعات مرتبط:
پروژه #c ,
پروژه طراحی الگورتم ,
,